# SERIALIZER

This's library for serialize primitive datatypes into byteorder

## Installation

Run these commands:
	meson build
	sudo ninja -C build/ install

## Example

Run these commands:
	mkdir src
	git clone https://notabug.org/penrose/libserializer.git subprojects/libserializer
	touch meson.build src/main.c

In meson.build:
	project('my_project', 'c')
	
	libserializer_proj = subproject('libserializer')
	libserializer_dep = libserializer_proj.get_variable('libserializer_dep')

	executable(
		meson.project_name(),
		sources: 'src/main.c',
		dependencies: libserializer_dep,
		install: true
	)

In src/main.c:
	#include <stdio.h>
	#include <stdint.h>
	#include "serializer.h"

	int
	main(void) {
		serializer_t serializer;
		if (serializer_init(&serializer) != 0) { // Initialize serializer_t
			return 1;
		}
		uint32_t write = 111;
		if (serializer_write_int(&serializer, write, Big) != 0) { // Write int into serializer_t
			return -1;
		}
		uint32_t read = 0;
		serializer.offset = 0; // When u write bytes into serializer_t offset of buffer increases
		if (serializer_read_int(&serializer, &read, Big) != 0) {
			return -1;
		}
		printf("integer, that wrote into serializer_t - %d.\n", write);
		printf("integer, that read from serializer_t - %d.\n", read);
		if (serializer_deinit(&serializer) != 0) { // Deinitialize serializer_t
			return 1;
		}
		return 0;
	}
	
